package org.xqp.hrm.service.impl;

import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.xqp.hrm.constants.BaseConstants;
import org.xqp.hrm.domain.Login;
import org.xqp.hrm.domain.Meal;
import org.xqp.hrm.mapper.MealMapper;
import org.xqp.hrm.service.IMealService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 套餐表 服务实现类
 * </p>
 *
 * @author xqp
 * @since 2021-11-22
 */
@Service
public class MealServiceImpl extends ServiceImpl<MealMapper, Meal> implements IMealService {

    @Autowired
    private MealMapper mealMapper;

    /**
     * 保存Login和套餐的中间表
     * @param mealId
     * @param loginId
     */
    @Override
    public void saveRelationWithLogin(Long mealId, Long loginId) {
        // 中间表中有个套餐时间 机构刚入住所以有个七天的试用时间
        Date expireTime = DateUtils.addDays(new Date(), 7); // 获取当前时间加上七天的时间
        mealMapper.saveRelationWithLogin(  mealId, // 套餐id
                                            loginId, // 机构管理账号id
                                            BaseConstants.Meal.STATE_UN_PAY, // 套餐支付状态
                                            expireTime); // 套餐试用到期时间
    }
}
